package com.itheima.web;

import com.itheima.result.Result;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.itheima.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.result.PageResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nobug")
public class UserController {
    @Autowired
    UserService userService;
    @PutMapping("/update")
    public Result update(User user){
        User user1 = userService.update(user);
        return Result.ok(user1);
    }
    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(@RequestParam(defaultValue = "1")Integer currentPage,
                            @RequestParam(defaultValue = "10")Integer pageSize ){
        PageResult pageResult = userService.pageQuery(currentPage,pageSize);
        return Result.ok(pageResult);
    }
    @DeleteMapping("{id}")
    public Result delById(@PathVariable Integer id){
        userService.delById(id);
        return Result.ok("成功删除");
    }
    @GetMapping("{id}")
    public Result findById(@PathVariable Integer id){
       User user = userService.findById(id);
        return Result.ok(user);
    }
}
